package org.listbeast.ui.internal;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.layout.GridData;
import org.listbeast.ui.internal.SWTResourceManager;

public class MainView extends ViewPart {

	public static final String ID = "org.listbeast.ui.internal.mainView"; //$NON-NLS-1$
	private Text txtMyTestView;
	private Text txtSelectSourceFolder;
	private Text sourceDirText;
	// private FormToolkit formToolkit;
	private Text txtMaximumNumberOf;
	private Text txtSelectDestFolder;
	private Text destDirText;
	private Button btnCopySelectedSongs;
	private Combo maxYoutubeResults;
	private Button startButton;
	private ProgressBar progressBar;
	private Text progressStatusText;
	private Button btnCreateMultiplePlaylists;

	public MainView() {
	}

	/**
	 * Create contents of the view part.
	 * 
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NONE);

		container.setLayout(new GridLayout(2, false));

		txtSelectSourceFolder = new Text(container, SWT.NONE);
		txtSelectSourceFolder.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
		txtSelectSourceFolder.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER,
				false, false, 2, 1));
		txtSelectSourceFolder.setEditable(false);
		txtSelectSourceFolder
				.setText("Select source folder containing your music files");

		GridData data = new GridData();
		data.grabExcessHorizontalSpace = true;
		data.horizontalAlignment = GridData.FILL;
		data.verticalAlignment = GridData.BEGINNING;

		sourceDirText = new Text(container, SWT.BORDER);
		GridData gd_sourceDirText = new GridData(SWT.FILL, SWT.CENTER, false,
				false, 1, 1);
		gd_sourceDirText.widthHint = 200;
		sourceDirText.setLayoutData(gd_sourceDirText);
		Button sourceButton = new Button(container, SWT.PUSH);
		sourceButton.setText("Browse...");
		/*
		 * sourceButton.addSelectionListener(new SelectionAdapter() { public
		 * void widgetSelected(SelectionEvent e) { DirectoryDialog dialog = new
		 * DirectoryDialog(shlListBeast); String platform = SWT.getPlatform();
		 * dialog.setFilterPath(platform.equals("win32") ||
		 * platform.equals("wpf") ? "c:\\" : "/"); String sourceDirectory =
		 * dialog.open(); if (sourceDirectory != null) {
		 * sourceDirText.setText(sourceDirectory); } } });
		 */
		txtSelectDestFolder = new Text(container, SWT.NONE);
		txtSelectDestFolder.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
		txtSelectDestFolder.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER,
				false, false, 2, 1));
		txtSelectDestFolder.setEditable(false);
		txtSelectDestFolder
				.setText("Select destination folder to store your playlist(s)");

		destDirText = new Text(container, SWT.BORDER);
		GridData gd_setDirText = new GridData(SWT.FILL, SWT.CENTER, false,
				false, 1, 1);
		gd_setDirText.widthHint = 180;
		destDirText.setLayoutData(gd_setDirText);
		// formToolkit.adapt(destDirText, true, true);

		Button destButton = new Button(container, SWT.NONE);
		destButton.setText("Browse...");
		/*
		 * destButton.addSelectionListener(new SelectionAdapter() { public void
		 * widgetSelected(SelectionEvent e) { DirectoryDialog dialog = new
		 * DirectoryDialog(shlListBeast); String platform = SWT.getPlatform();
		 * dialog.setFilterPath(platform.equals("win32") ||
		 * platform.equals("wpf") ? "c:\\" : "/"); String destinationDirectory =
		 * dialog.open(); if (destinationDirectory != null) {
		 * destDirText.setText(destinationDirectory); } } });
		 */
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);

		txtMaximumNumberOf = new Text(container, SWT.NONE);
		txtMaximumNumberOf.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
		txtMaximumNumberOf.setEditable(false);
		txtMaximumNumberOf.setText("Max number of youtube results per artist");

		ComboViewer comboViewer = new ComboViewer(container, SWT.NONE);
		maxYoutubeResults = comboViewer.getCombo();
		GridData gd_maxYoutubeResults = new GridData(SWT.LEFT, SWT.CENTER,
				false, false, 1, 1);
		gd_maxYoutubeResults.widthHint = 95;
		maxYoutubeResults.setLayoutData(gd_maxYoutubeResults);
		maxYoutubeResults.setItems(new String[] { "1", "2", "3", "4", "5", "6",
				"7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17",
				"18", "19", "20" });
		// formToolkit.paintBordersFor(maxYoutubeResults);
		maxYoutubeResults.select(0);

		btnCopySelectedSongs = new Button(container, SWT.CHECK | SWT.RIGHT);
		GridData gd_btnCopySelectedSongs = new GridData(SWT.LEFT, SWT.CENTER,
				false, false, 2, 1);
		gd_btnCopySelectedSongs.horizontalIndent = 4;
		btnCopySelectedSongs.setLayoutData(gd_btnCopySelectedSongs);
		btnCopySelectedSongs.setAlignment(SWT.LEFT);
		btnCopySelectedSongs
				.setText("Copy selected songs to destination folder");

		btnCreateMultiplePlaylists = new Button(container, SWT.CHECK
				| SWT.RIGHT);
		GridData gd_btnCreateMultiplePlaylists = new GridData(SWT.LEFT,
				SWT.CENTER, false, false, 1, 1);
		gd_btnCreateMultiplePlaylists.horizontalIndent = 4;
		btnCreateMultiplePlaylists.setLayoutData(gd_btnCreateMultiplePlaylists);
		btnCreateMultiplePlaylists
				.setText("Create different playlist per artist");
		btnCreateMultiplePlaylists.setAlignment(SWT.LEFT);
		new Label(container, SWT.NONE);

		Label label_10 = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
		GridData gd_label_10 = new GridData(SWT.CENTER, SWT.FILL, false, false,
				1, 1);
		gd_label_10.widthHint = 281;
		label_10.setLayoutData(gd_label_10);
		new Label(container, SWT.NONE);

		startButton = new Button(container, SWT.NONE);
		GridData gd_btnNewButton = new GridData(SWT.CENTER, SWT.CENTER, false,
				false, 1, 1);
		gd_btnNewButton.widthHint = 364;
		startButton.setLayoutData(gd_btnNewButton);
		/*
		 * startButton.addSelectionListener(new SelectionAdapter() {
		 * 
		 * @Override public void widgetSelected(SelectionEvent e) { ListBeastApp
		 * myApp; try { myApp = new ListBeastApp(destDirText.getText(),
		 * sourceDirText.getText(), Integer
		 * .valueOf(maxYoutubeResults.getText()),
		 * btnCopySelectedSongs.getSelection(),
		 * btnCreateMultiplePlaylists.getSelection());
		 * 
		 * myApp.registerObserver(ListBeastSWT.this); Thread popApp = new
		 * Thread(myApp); popApp.start(); } catch (ApplicationException e1) { //
		 * Create the required Status object Status status = new
		 * Status(IStatus.ERROR, "My Plug-in ID", 0, e1.getMessage(), null);
		 * 
		 * // Display the dialog
		 * ErrorDialog.openError(Display.getCurrent().getActiveShell(), "Error",
		 * "An error has occured", status); } } });
		 */
		startButton.setText("Start");
		new Label(container, SWT.NONE);

		progressBar = new ProgressBar(container, SWT.SMOOTH);
		progressBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
				false, 1, 1));
		// formToolkit.adapt(progressBar, true, true);
		new Label(container, SWT.NONE);

		progressStatusText = new Text(container, SWT.NONE);
		progressStatusText.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
		progressStatusText.setEditable(false);
		progressStatusText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
				true, false, 2, 1));

		createActions();
		initializeToolBar();
		initializeMenu();
	}

	/**
	 * Create the actions.
	 */
	private void createActions() {
		// Create the actions
	}

	/**
	 * Initialize the toolbar.
	 */
	private void initializeToolBar() {
		IToolBarManager toolbarManager = getViewSite().getActionBars()
				.getToolBarManager();
	}

	/**
	 * Initialize the menu.
	 */
	private void initializeMenu() {
		IMenuManager menuManager = getViewSite().getActionBars()
				.getMenuManager();
	}

	@Override
	public void setFocus() {
		// Set the focus
	}

}
